// Copyright (c) 2009 Alistair Jones
// This program is made available under the terms of the MIT License.
package org.hypirinha.html.codegen;

import static org.hypirinha.html.codegen.CodegenUtil.capitalise;
import static org.hypirinha.html.codegen.CodegenUtil.removeSpecialCharacters;

import java.util.SortedSet;
import java.util.TreeSet;

public class Attribute {

    private String name;
    private SortedSet<String> applicableElements = new TreeSet<String>();

    public Attribute(String name) {
        this.name = removeSpecialCharacters(name);
    }

    public void addApplicableElement(String elementName) {
        applicableElements.add(elementName);
    }

    public GeneratedClass createAttributeImplementation() {
        GeneratedClass generatedClass = new GeneratedClass("org.hypirinha.html.attributes", capitalise(name) + "Attribute");
        generatedClass.addImport("org.hypirinha.html.elements.*");
        if (applicableElements.contains("object")) {
            generatedClass.addImport("org.hypirinha.html.elements.Object");
        }
        generatedClass.setSuperClass("Attribute");
        for (String applicableElement : applicableElements) {
            generatedClass.addInterface(capitalise(applicableElement) + ".Attribute");
        }
        generatedClass.getMembers().add(new Constructor(capitalise(name) + "Attribute", "String attributeValue",
                "super(\"" + name + "\", attributeValue);"));
        return generatedClass;
    }
}